package com.example.web.controller;

import com.example.common.basic.MultiRequestBody;
import com.example.common.response.R;
import com.example.system.domain.Item;
import com.example.system.domain.bo.ItemBo;
import com.example.system.domain.bo.PageBo;
import com.example.system.domain.vo.PageVo;
import com.example.system.others.perm.PermInter;
import com.example.system.service.ItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@Api(value = "项目管理", tags = {"项目管理"})
@RequestMapping(value = "/item", method = {RequestMethod.POST, RequestMethod.GET})
public class ItemController {
    @Autowired
    public ItemService itemService;

    @ResponseBody
    @ApiOperation("获取项目列表")
    @RequestMapping(value = "/getList")
    public R<PageVo<Item>> getList(@RequestBody PageBo pageBo) {
        return R.ok(itemService.getList(pageBo));
    }

    @ResponseBody
    @ApiOperation("搜索项目列表")
    @RequestMapping(value = "/getList/search")
    public R<PageVo<Item>> itemListsSearch(@MultiRequestBody String name, @MultiRequestBody PageBo pageBo) {
        return itemService.itemListsSearch(name, pageBo);
    }

    @ResponseBody
    @ApiOperation("添加项目")
    @RequestMapping(value = "/insert")
    public R<String> insert(@RequestBody ItemBo itemBo) {
        itemService.insert(itemBo);
        return R.ok("添加成功");
    }

    @ResponseBody
    @ApiOperation("删除项目")
    @RequestMapping(value = "/delete")
    public R<PageVo<Item>> delete(@MultiRequestBody String projectId, @MultiRequestBody String itemId, @MultiRequestBody PageBo pageBo) {
        return itemService.delete(projectId, itemId, pageBo);
    }

    @ResponseBody
    @ApiOperation("修改项目")
    @RequestMapping(value = "/update")
    public R<PageVo<Item>> update(@MultiRequestBody ItemBo itemBo, @MultiRequestBody PageBo pageBo) {
        return itemService.update(itemBo, pageBo);
    }

    @ResponseBody
    @ApiOperation("获取我的项目列表")
    @RequestMapping(value = "/getList/MyItem")
    public R<PageVo<Item>> myItem(@RequestBody PageBo pageBo) {
        return R.ok(itemService.myItem(pageBo));
    }

    @ResponseBody
    @ApiOperation("搜索我的项目列表")
    @RequestMapping(value = "/getList/MyItem/search")
    public R<PageVo<Item>> myItemSearch(@MultiRequestBody String name, @MultiRequestBody PageBo pageBo) {
        PageVo<Item> items = itemService.myItemSearch(name, pageBo);
        if (items.getTotal() == 0)
            return R.info("没有符合条件的数据", new PageVo<>());
        return R.ok(items);
    }

    @ResponseBody
    @ApiOperation("获取当前用户审核列表")
    @RequestMapping(value = "/getList/Process")
    @PermInter(perm = ":item:getList:Process", name = "获取当前用户审核列表", jsjb = "2")
    public R<PageVo<Item>> getProcessList(@RequestBody PageBo pageBo) {
        PageVo<Item> items = itemService.getProcessList(pageBo);
        return R.ok(items);
    }

    @ResponseBody
    @ApiOperation("搜索当前用户审核列表")
    @RequestMapping(value = "/getList/Process/search/{name}")
    @PermInter(perm = ":item:getList:Process:search", name = "搜索当前用户审核列表", jsjb = "2")
    public R<PageVo<Item>> getProcessListSearch(@RequestBody PageBo pageBo, @PathVariable("name") String name) {
        PageVo<Item> items = itemService.getProcessListSearch(pageBo, name);
        if (items.getTotal() == 0)
            return R.info("没有符合条件的数据", new PageVo<>());
        return R.ok(items);
    }
}
